<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"
	import="java.util.Date,java.text.SimpleDateFormat,Reservation.UserBean,Application.Dao.ReservationDAO,DomainData.Reservation"%>

	<%
		UserBean currentUser = (UserBean) session.getAttribute("currentSessionUser");
		if (currentUser == null) {
			response.sendRedirect("Login.jsp");
			return;
		}		
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

		Date from = formatter.parse(request.getParameter("from"));
		Date to =  formatter.parse(request.getParameter("to"));
		int numberOfPeople = Integer.parseInt(request.getParameter("numberOfPeople"));
		int tableID = ReservationDAO.getTable(from,to,numberOfPeople);
		if(tableID==-1){
			out.println("No table Availble for the given Time");
			out.println("Please select another period of time.");
		}
		else{
			int userID = currentUser.getUserID();
			Reservation reservation = new Reservation(0,from,to,numberOfPeople,tableID,userID);
			int reservationID = ReservationDAO.insertReservation(reservation);
			out.print(reservationID+","+tableID);
		}
	%>
	